let t = require;
let e = module;
let o = e.exports;
o.default = e.exports;

('use strict');
console.log('start');
var _n62,
  i =
    (this && this.__extends) ||
    ((_n62 = function n(t, e) {
      return (_n62 =
        Object.setPrototypeOf ||
        ({
          __proto__: []
        } instanceof Array &&
          function (t, e) {
            t.__proto__ = e;
          }) ||
        function (t, e) {
          for (var o in e) {
            Object.prototype.hasOwnProperty.call(e, o) && (t[o] = e[o]);
          }
        })(t, e);
    }),
      function (t, e) {
        function o() {
          this.constructor = t;
        }
        _n62(t, e),
          (t.prototype =
            null === e
              ? Object.create(e)
              : ((o.prototype = e.prototype), new o()));
      });
Object.defineProperty(o, '__esModule', {
  value: !0
}),
  (o.CardType1Com = void 0);
var r = t('UIComponent'),
  a = t('ComUtils'),
  s = t('BagMrg'),
  c = t('ResMrg'),
  l = t('SoundMrg'),
  u = t('AbsInfo'),
  h = t('UIMrg'),
  p = t('CardUpgradePanel'),
  f = t('GameSDK'),
  d = t('BattleUtils'),
  g = t('LangCfg'),
  _ = (function (t) {
    function e(e, o) {
      var n = t.call(this, e) || this;
      return (
        (e.active = !0),
        (n._battleInfo = o),
        n._battleInfo.on(u.InfoEvent.StateChanged, n.onBattleChangedHandler, n),
        n.refreshUI(),
        n
      );
    }
    return (
      i(e, t),
      (e.prototype.onInit = function () {
        t.prototype.onInit.call(this),
          (this._imgBg = a.default.getNode(this.view, 'imgBg')),
          (this._imgAdd = a.default.getNode(this.view, 'imgAdd')),
          (this._btnOpen = a.default.getNode(this.view, 'btnOpen')),
          (this._card = a.default.getNode(this.view, 'card')),
          (this._imgFrame = a.default.getComponent(
            cc.Sprite,
            this.view,
            'card'
          )),
          (this._imgIcon = a.default.getComponent(
            cc.Sprite,
            this.view,
            'card/imgIcon'
          )),
          (this._imgQuality = a.default.getComponent(
            cc.Sprite,
            this.view,
            'card/imgQuality'
          )),
          (this._pbBar = a.default.getComponent(
            cc.ProgressBar,
            this.view,
            'card/progress'
          )),
          (this._txtCount = a.default.getComponent(
            cc.Label,
            this.view,
            'card/progress/txtCount'
          )),
          (this._txtLevel = a.default.getComponent(
            cc.Label,
            this.view,
            'card/txtLevel'
          )),
          (this._txtName = a.default.getComponent(
            cc.Label,
            this.view,
            'card/txtName'
          )),
          (this._txtManJi = a.default.getComponent(
            cc.Label,
            this.view,
            'card/txtManJi'
          )),
          (this._upgradeTips = a.default.getNode(
            this.view,
            'card/progress/upgradeTips'
          )),
          this._btnOpen.on(
            cc.Node.EventType.TOUCH_END,
            this.onTouchAdHandler,
            this
          );
      }),
      (e.prototype.onLang = function () {
        var t = a.default.getComponent(cc.Label, this.view, 'btnOpen/Label');
        (t.string = g.LangCfg.ins.getContent(200703)),
          ((t = a.default.getComponent(
            cc.Label,
            this.view,
            'card/txtManJi'
          )).string = g.LangCfg.ins.getContent(1019)),
          this._info &&
          (this._txtName.string = g.LangCfg.ins.getContent(this._info.name));
      }),
      (e.prototype.onTouchEvenHandler = function (t) {
        t.type == cc.Node.EventType.TOUCH_END &&
          this._battleInfo.isOpen &&
          this._battleInfo.card &&
          (l.SoundMrg.click(), h.UIMrg.show(p.CardUpgradePanel, this._info));
      }),
      (e.prototype.onTouchAdHandler = function () {
        l.SoundMrg.click(),
          f.default.showVideoAd(this.onAdCallBackHandler, this);
      }),
      (e.prototype.onAdCallBackHandler = function () {
        this._battleInfo.open();
      }),
      (e.prototype.onBattleChangedHandler = function () {
        this.refreshUI();
      }),
      (e.prototype.refreshUI = function () {
        // 获取当前视图的 Button 组件
        const buttonComponent = this.view.getComponent(cc.Button);
        // 检查战斗信息是否已开启
        if (this._battleInfo.isOpen) {
          // 如果存在卡片信息，移除背包数量变化事件监听
          if (this._info) {
            s.BagMrg.ins.removeCountEvent(
              this._info.itemId,
              this.refreshOther,
              this
            );
          }
          // 如果存在战斗卡片
          if (this._battleInfo.card) {
            // 监听卡片等级变化事件
            this._battleInfo.card.on(
              u.InfoEvent.LevelChanged,
              this.refreshOther,
              this
            );
            // 添加背包数量变化事件监听
            s.BagMrg.ins.addCountEvent(
              this._battleInfo.card.itemId,
              this.refreshOther,
              this
            );
          }
          // 更新当前卡片信息
          this._info = this._battleInfo.card;

          if (this._battleInfo.card) {
            // 显示卡片，隐藏添加图标和背景
            this._card.active = true;
            this._imgAdd.active = false;
            this._imgBg.active = false;
            // 启用按钮交互
            buttonComponent.interactable = true;
            // 刷新卡片信息
            this.refreshCard();
          } else {
            // 隐藏卡片，显示添加图标和背景
            this._card.active = false;
            this._imgAdd.active = true;
            this._imgBg.active = true;
            // 禁用按钮交互
            buttonComponent.interactable = false;
          }
          // 隐藏打开按钮
          this._btnOpen.active = false;
        } else {
          // 获取打开按钮内的文本组件并更新显示内容
          const btnLabel = a.default.getComponent(
            cc.Label,
            this._btnOpen,
            'Background/New Layout/txtValue'
          );
          btnLabel.string =
            this._battleInfo.adVideoCount +
            '/' +
            this._battleInfo.maxAdVideoCount;
          // 显示背景和打开按钮，隐藏添加图标和卡片
          this._imgBg.active = true;
          this._btnOpen.active = true;
          this._imgAdd.active = false;
          this._card.active = false;
          // 禁用按钮交互
          buttonComponent.interactable = false;
        }

      }),
      (e.prototype.refreshCard = function () {
        var t = this._txtName.node.getComponent(cc.LabelOutline);
        c.ResMrg.loadSpriteByAtlas(
          this._imgFrame,
          'Atlas/Card',
          'frame' + this._info.quality
        ),
          c.ResMrg.loadSpriteByAtlas(
            this._imgIcon,
            'Atlas/Card',
            this._info.icon
          ),
          c.ResMrg.loadSpriteByAtlas(
            this._imgQuality,
            'Atlas/Card',
            'quality' + this._info.quality
          ),
          (this._txtName.string = g.LangCfg.ins.getContent(this._info.name)),
          (t.color = cc.Color.fromHEX(
            t.color,
            d.default.CardNameOutLineColors[this._info.quality]
          )),
          this.refreshOther();
      }),
      (e.prototype.refreshOther = function () {
        if (
          ((this._txtLevel.string = 'Lv.' + this._info.level),
            this._info.isMaxLevel)
        )
          (this._pbBar.node.active = !1), (this._txtManJi.node.active = !0);
        else {
          var t = s.BagMrg.ins.getCount(this._info.itemId);
          (this._upgradeTips.active = t >= this._info.itemCount),
            (this._txtCount.string =
              Math.min(t, this._info.itemCount) + '/' + this._info.itemCount),
            cc
              .tween(this._pbBar)
              .to(0.1, {
                progress: Math.min(t / this._info.itemCount, 1)
              })
              .start(),
            (this._pbBar.node.active = !0),
            (this._txtManJi.node.active = !1);
        }
      }),
      e
    );
  })(r.UIComponent);
(o.CardType1Com = _), console.log('end');
module.exports = e.exports;
